﻿using Hotel.Application;
using Hotel.Application.Admins;
using Hotel.Application.Admins.Dto;
using Hotel.Domain;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace Hotel.Web.Controllers
{
    /// <summary>
    /// 管理员测试
    /// </summary>
    [Authorize]
    public class AdminController : BaseController<Admin, AdminCreateUpdateDto, AdminListDto>
    {
        private readonly IBaseService<Admin, AdminCreateUpdateDto, AdminListDto> service;
        private readonly IAdminService adminService;

        
        public AdminController(
            IBaseService<Admin, AdminCreateUpdateDto, AdminListDto> service,
            IAdminService adminService
            ) : base(service)
        {
            this.service = service;
            this.adminService = adminService;
        }

        public IAdminService AdminService { get; set; }

        [HttpGet]
        public async Task<IActionResult> Test()
        {
            var a = await AdminService.QueryAsync();
            return Ok();
        }

        [HttpGet]
        public async Task<IActionResult> ToPageListAsync(QueryDto dto, int PageSize = 10, int PageIndex = 1)
        {            
            Expressionable<Admin> exp = new Expressionable<Admin>();
            exp.AndIF(!string.IsNullOrWhiteSpace(dto.Keywords), it => it.UserName.Contains(dto.Keywords));
            exp.AndIF(dto.StartTime != null, it => it.CreateTime >= dto.StartTime);
            exp.AndIF(dto.EndTime != null, it => it.CreateTime <= dto.EndTime);
            var page = await base.PageAsync(exp, PageSize, PageIndex);
            return page;
        }

        [HttpGet]
        public async Task<IActionResult> CheckName(string UserName,long AdminId)
        {
            return Ok(await adminService.CheckName(UserName, AdminId));
        }

        [HttpPost]
        public override Task<IActionResult> Edit(AdminCreateUpdateDto dto)
        {
            return base.Edit(dto);
        }
    }
}
